<?php
/**
 * $Id: image.php 71 2008-12-25 07:28:33Z gpo_gigapromoters $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * This is parent of parent class of a controller and should not be edited ever without permission.
 * @version 			$Rev: 71 $
 * @lastModifiedBy		$LastChangedBy: gpo_gigapromoters $
 * @lastChanged			$Date: 2008-12-25 12:58:33 +0530 (Thu, 25 Dec 2008) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * This helper works with the Upload behavior to return the small/medium images for any uploaded image.
 * Very handy when you need to display small/medium image but have name of original image only.
 *
 */
class ImageHelper extends AppHelper {

	//var $helpers = array('Javascript', 'Html');

	var $uploadsDir = 'uploads';

	function __construct()
	{
		$this->uploadsDir = APP.DS.'webroot'.DS.$this->uploadsDir;
	}

	/**
	 * Returns thumb based on $size Also confirms if a thumb exists before the output.
	 *
	 * @param unknown_type $image
	 * @param unknown_type $size
	 * @param unknown_type $extFolder
	 * @return unknown
	 */
	function getThumb($image, $size='small', $extFolder=Null)
	{
		if(!$image || $image=='')
		{
			return false;
		}

		@list($file, $ext) = explode('.', $image);
		$newFilename = $file.'.'.$size.'.'.$ext;

		if($extFolder)
			$file_path=$this->uploadsDir.DS.$extFolder.DS;
		else
			$file_path=$this->uploadsDir.DS;
		
		// add verification if this thumb really exists
		if(file_exists($file_path.$newFilename))
			return $newFilename;
		else
			return $image;   // return old filename as it is
	}


}
?>